home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / lang / PPCSmllEiffel.lha / PPCSmallEiffel / lib_se / loop_variant.e < prev    next >
Text File  |  1998-01-16  |  2KB  |  99 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. deferred class LOOP_VARIANT
  17. --
  18. -- For a variant clause of a loop.
  19. -- 
  20. -- Classification : 
  21. --    LOOP_VARIANT_1 : no tag.
  22. --    LOOP_VARIANT_2 : with tag.
  23. --
  24.  
  25. inherit GLOBALS;
  26.  
  27. feature
  28.    
  29.    comment: COMMENT;
  30.    
  31.    expression: EXPRESSION;
  32.  
  33.    current_type: TYPE;
  34.  
  35. feature
  36.  
  37.    use_current: BOOLEAN is
  38.       do
  39.      Result := expression.use_current;
  40.       end;
  41.    
  42.    pretty_print is
  43.       deferred
  44.       end;
  45.    
  46.    start_position: POSITION is
  47.       do
  48.      Result := expression.start_position;
  49.       end;
  50.    
  51.    to_runnable(ct: TYPE): like Current is
  52.       local
  53.      e: like expression;
  54.       do
  55.      if current_type = Void then
  56.         current_type := ct;
  57.         e := expression.to_runnable(ct);
  58.         if e = Void then
  59.            error(start_position,"Bad loop variant.");
  60.         else
  61.            expression := e;
  62.            if not expression.result_type.is_integer then
  63.           error(expression.start_position,
  64.             "Expression of variant must be INTEGER.");
  65.            end;
  66.         end;
  67.         if nb_errors = 0 then
  68.            Result := Current;
  69.         end;
  70.      else
  71.         Result := twin;
  72.         Result.set_current_type(Void);
  73.         Result := Result.to_runnable(ct);
  74.      end;
  75.       end;
  76.  
  77. feature {E_LOOP}
  78.  
  79.    afd_check is
  80.       do
  81.      expression.afd_check;
  82.       end;
  83.  
  84. feature {LOOP_VARIANT}
  85.    
  86.    set_current_type(ct: like current_type) is
  87.       do
  88.      current_type := ct;
  89.       ensure
  90.      current_type = ct;
  91.       end;
  92.    
  93. invariant
  94.    
  95.    expression /= Void
  96.    
  97. end -- LOOP_VARIANT
  98.  
  99.